home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 May: Tool Chest / Developer CD Series Tool Chest (Apple Computer)(May 1999).iso / Tool Chest / Games / Game Sample Code / ZAM 1.0a13 / GameSource / IncidentalSounds.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-09-16  |  1.3 KB  |  69 lines  |  [TEXT/KAHL]

  1. /*
  2.  
  3.     This file contains just a little code that uses the xthing timer
  4.     to play sounds every once in a while.
  5. */
  6. #include "ZAM.h"
  7. #include "GameSounds.h"
  8. #include "TankSprite.h"
  9. #include <Math.h>
  10. #include "ZAMProtos.h"
  11.  
  12.  
  13. xthing gIncidentalSoundTask;
  14. static gLastSound;
  15.  
  16. Boolean IncidentalSoundTask(xthing *xtp, long ignore)
  17. {
  18.     short     x;
  19.     short    soundID = 0;
  20.     
  21.     x = abs(Random() % 7);
  22.     
  23.     if(x == 1)
  24.         if(gLastSound == kIncidental1)
  25.             soundID = kIncidental3;
  26.         else
  27.             soundID = kIncidental1;
  28.     else if (x == 2)
  29.         if(gLastSound == kIncidental2)
  30.             soundID = kIncidental1;
  31.         else
  32.             soundID = kIncidental2;
  33.     else if (x == 3)
  34.         if(gLastSound == kIncidental3)
  35.             soundID = kIncidental4;
  36.         else
  37.             soundID = kIncidental3;
  38.     else if (x == 4)
  39.         if(gLastSound == kIncidental4)
  40.             soundID = kIncidental5;
  41.         else
  42.             soundID = kIncidental4;
  43.     else if (x == 5)
  44.         if(gLastSound == kIncidental5)
  45.             soundID = kIncidental2;
  46.         else
  47.             soundID = kIncidental5;
  48.  
  49.     if(soundID != 0) {
  50.         gLastSound = soundID;
  51.         (void)PlaySndAsynchChannel(gLastSound, kMusicChan, kStdPriority);
  52.     }
  53.     
  54.     /* play next sound in a random amount of time, from 5 to 30 seconds from now */
  55.     xtp->interval = ( (Random() & 0x7FFFF) % 25000) + 5000;
  56.     
  57.     return true;
  58. }
  59.  
  60. void StartIncidentalSounds(void)
  61. {
  62.     gLastSound = 0;
  63.     (void)StartXThing(&gIncidentalSoundTask, 30000, 
  64.             (updateProc)IncidentalSoundTask, 0L);
  65. }
  66.  
  67.  
  68.  
  69.